<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js星级评分点击星级评论打分效果</title>
<meta name="description" content="js星级评论打分系统，制作鼠标滑过星级提示星级描述，点击星级评论打分效果。js代码" />
<link rel="stylesheet" type="text/css" href="<%=path %>/css/star.css">
<script type="text/javascript"> 
	window.onload = function (){

	var oStar = document.getElementById("star");
	var aLi = oStar.getElementsByTagName("li");
	var oUl = oStar.getElementsByTagName("ul")[0];
	var oSpan = oStar.getElementsByTagName("span")[0];
	var oP = oStar.getElementsByTagName("p")[0];
	var i = iScore = iStar = 0;
	fnPoint(4);
	var aMsg = [
				"很容易|非常容易",
				"容易|容易",
				"一般|难易程度一般",
				"有点难|有点难",
				"非常难|非常难"
				]
	
	for (i = 1; i <= aLi.length; i++){
		aLi[i - 1].index = i;
		//鼠标移过显示分数
		aLi[i - 1].onmouseover = function (){
			//浮动层显示
			oP.style.display = "block";
			//计算浮动层位置
			oP.style.left = oUl.offsetLeft + this.index * this.offsetWidth - 104 + "px";
			//匹配浮动层文字内容
			oP.innerHTML = "<em><b>" + this.index + "</b> 星 " + aMsg[this.index - 1].match(/(.+)\|/)[1] + "</em>" + aMsg[this.index - 1].match(/\|(.+)/)[1];
		};
		//鼠标离开后恢复上次评分
		aLi[i - 1].onmouseout = function (){
			oP.style.display = "none"
		};
	}
	
	//评分处理
	function fnPoint(iArg){
		//分数赋值
		iScore = iArg || iStar;
		for (i = 0; i < aLi.length; i++){
			aLi[i].className = i < iScore ? "on" : "";	
		}
	}
};
</script>
</head>

<body>
<!--star start-->
	<div id="star">
		<ul>
			<li>1</li>
			<li>2</li>
			<li>3</li>
			<li>4</li>
			<li>5</li>
		</ul>
		<span></span>
		<p></p>
	</div>
<!--star end-->
</body>
</html>